<!-- <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>函数的扩展 - 形参的默认值</title>
</head>
<body>
  <script>
    //声明函数时，参数设置一个默认值
    function add(a = 10, b = 20){
      console.log(a + b);
    };
    //函数调用时，不传入实参，则会使用默认值进行运算
    add();//30
    //函数调用时，传入实参，则会使用实参进行运算
    add(3,5);//8
    add(6);//26
  </script>
</body>
</html> -->

<!-- <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>函数的扩展 - 解构赋值搭配形参的默认值</title>
</head>
<body>
  <script>
    function add ({a, b = 10}){
      //实质上是这样解构赋值的 {a,b} = {a:1, b:5} 
      console.log(a + b);
    }
    add({a:1, b:5});//6
    add({a:1});//11
  </script>
</body>
</html> -->

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>函数的扩展 - rest参数(可变参数)</title>
</head>
<body>
  <script>
    function add(){
      console.log(arguments);
    }
    add(10, 12, 23, 35, 68);
    //函数调用时，所有参数都会以数组形式保存在 args 变量中
    // rest参数 指的就是 扩展运算符+变量这里是(...args)
    function add1(...args){
      console.log(args);
    }
    add1(10, 12, 23, 35, 68);

    //演示一点点的$.get()方法
    function get(...args){
      for(let i = 0; i < args.length; i++){
        if(typeof(args[i]) == 'number'){
          console.log(`参数${i}是数值类型`);

        }else if(typeof(args[i] == 'string')){
          console.log(`参数${i}是字符串类型`);
        };
      };    
    };
    get(10,'abc',function(){});
  </script>
</body>
</html>